/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class PacientDAO {
	public static Pacient loadPacientByORMID(int idPaciente) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadPacientByORMID(session, idPaciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient getPacientByORMID(int idPaciente) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getPacientByORMID(session, idPaciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient loadPacientByORMID(int idPaciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadPacientByORMID(session, idPaciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient getPacientByORMID(int idPaciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getPacientByORMID(session, idPaciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient loadPacientByORMID(PersistentSession session, int idPaciente) throws PersistentException {
		try {
			return (Pacient) session.load(orm.Pacient.class, new Integer(idPaciente));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient getPacientByORMID(PersistentSession session, int idPaciente) throws PersistentException {
		try {
			return (Pacient) session.get(orm.Pacient.class, new Integer(idPaciente));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient loadPacientByORMID(PersistentSession session, int idPaciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pacient) session.load(orm.Pacient.class, new Integer(idPaciente), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient getPacientByORMID(PersistentSession session, int idPaciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pacient) session.get(orm.Pacient.class, new Integer(idPaciente), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient[] listPacientByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listPacientByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient[] listPacientByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listPacientByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient[] listPacientByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pacient as Pacient");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Pacient[]) list.toArray(new Pacient[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient[] listPacientByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pacient as Pacient");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Pacient[]) list.toArray(new Pacient[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient loadPacientByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadPacientByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient loadPacientByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadPacientByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient loadPacientByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Pacient[] pacients = listPacientByQuery(session, condition, orderBy);
		if (pacients != null && pacients.length > 0)
			return pacients[0];
		else
			return null;
	}
	
	public static Pacient loadPacientByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Pacient[] pacients = listPacientByQuery(session, condition, orderBy, lockMode);
		if (pacients != null && pacients.length > 0)
			return pacients[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePacientByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iteratePacientByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePacientByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iteratePacientByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePacientByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pacient as Pacient");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePacientByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Pacient as Pacient");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient createPacient() {
		return new orm.Pacient();
	}
	
	public static boolean save(orm.Pacient pacient) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().saveObject(pacient);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm.Pacient pacient) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().deleteObject(pacient);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Pacient pacient)throws PersistentException {
		try {
			if(pacient.getDiagnose() != null) {
				pacient.getDiagnose().setPacientidPaciente(null);
			}
			
			if(pacient.getResponse() != null) {
				pacient.getResponse().setPacientidPaciente(null);
			}
			
			return delete(pacient);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.Pacient pacient, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(pacient.getDiagnose() != null) {
				pacient.getDiagnose().setPacientidPaciente(null);
			}
			
			if(pacient.getResponse() != null) {
				pacient.getResponse().setPacientidPaciente(null);
			}
			
			try {
				session.delete(pacient);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm.Pacient pacient) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().refresh(pacient);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm.Pacient pacient) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().evict(pacient);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Pacient loadPacientByCriteria(PacientCriteria pacientCriteria) {
		Pacient[] pacients = listPacientByCriteria(pacientCriteria);
		if(pacients == null || pacients.length == 0) {
			return null;
		}
		return pacients[0];
	}
	
	public static Pacient[] listPacientByCriteria(PacientCriteria pacientCriteria) {
		return pacientCriteria.listPacient();
	}
}
